package com.sky.controller.user;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RequiredArgsConstructor
@Slf4j
@RestController
@RequestMapping("/user/order")
public class OrdersController {
    /**
     * 订单服务
     */
    private final OrdersService ordersService;

    /**
     * 页
     *
     * @param ordersPageQueryDTO 订单页面查询dto
     * @return {@link Result}<{@link PageResult}>
     */
    @GetMapping("/historyOrders")
    public Result<PageResult> page(OrdersPageQueryDTO ordersPageQueryDTO){
        PageResult pageResult = ordersService.page(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 按id获取订单
     *
     * @param id id
     * @return {@link Result}<{@link ?}>
     */
    @GetMapping("/orderDetail/{id}")
    public Result<?> getOrdersById(@PathVariable String id) {
        OrderVO orders = ordersService.getOrdersById(id);
        return Result.success(orders);
    }

    /**
     * 按id获取提醒
     *
     * @param id id
     * @return {@link Result}<{@link ?}>
     */
    @GetMapping("/reminder/{id}")
    public Result<?> getReminderById(@PathVariable Long id) {
        ordersService.getReminderById(id);
        return Result.success();
    }

    /**
     * 按id获取重复
     *
     * @param id id
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping("/repetition/{id}")
    public Result<?> getRepetitionById(@PathVariable String id) {
        ordersService.getRepetitionById(id);
        return Result.success();
    }

    /**
     * 插入提交
     *
     * @param ordersSubmitDTO 订单提交dto
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping("/submit")
    public Result<?> insertSubmit(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
        OrderSubmitVO orderSubmitVO = ordersService.insertSubmit(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }

    /**
     * 按id取消
     *
     * @param id id
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping("/cancel/{id}")
    public Result<?> getCancelById(@PathVariable Long id) {
        ordersService.getCancelById(id);
        return Result.success();
    }

    @GetMapping("/paySuccess/{number}")
    public Result<?> paySuccess(@PathVariable String number) {
        ordersService.paySuccess(number);
        return Result.success();
    }
}
